package com.yanghui.dtracing.core.utils;

import cn.hutool.core.util.StrUtil;

public class TracingUtil {

    private static String P_ID_CACHE = null;

    public static String getPID() {
        //check pid is cached
        if (P_ID_CACHE != null) {
            return P_ID_CACHE;
        }
        String processName = java.lang.management.ManagementFactory.getRuntimeMXBean().getName();

        if (StrUtil.isBlank(processName)) {
            return "";
        }

        String[] processSplitName = processName.split("@");

        if (processSplitName.length == 0) {
            return "";
        }

        String pid = processSplitName[0];

        if (StrUtil.isBlank(pid)) {
            return "";
        }
        P_ID_CACHE = pid;
        return pid;
    }
}
